package abacab.serial;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

/**
 * A standard Java serializer
 */
public class JavaSerializer implements Serializer {
	@Override
	public boolean isClassNameNeeded() {
		return false;
	}

	@Override
	public void encode(Object obj, OutputStream os) throws IOException {
		ObjectOutputStream oos = new ObjectOutputStream(os);
		oos.writeObject(obj);
	}

	@Override
	@SuppressWarnings("rawtypes")
	public Object decode(InputStream is, Class clazz) throws IOException, ClassNotFoundException {
		ObjectInputStream ois = new ObjectInputStream(is);
		return ois.readObject();
	}

	@Override
	public void dispose() {
		// nothing to do
	}
}